<script>
	import {
		Token
	} from './common/token.js'
	let tokenModel = new Token()
	export default {
		onLaunch: function() {
			tokenModel.verify()
			const menuButtonObject = uni.getMenuButtonBoundingClientRect()
			uni.getSystemInfo({
				success: res => {
					let statusBarHeight = res.statusBarHeight,
						navTop = menuButtonObject.top, //胶囊按钮与顶部的距离
						navHeight = 4 + statusBarHeight + menuButtonObject.height + (menuButtonObject.top -
							statusBarHeight) * 2; //导航高度
					this.globalData.navHeight = navHeight
					this.globalData.navTop = navTop
					this.globalData.windowHeight = res.windowHeight
					this.globalData.windowWidth = res.windowWidth
					this.globalData.menuButtonHeight = menuButtonObject.height
				},
				fail(err) {
					console.log(err);
				}
			})
			const currentDate = {
				currentDate: '',
				currentHour: '',
				nextDate: '',
				nextHour: ''
			}
			const date = new Date()
			const year = date.getFullYear()
			const month = (date.getMonth() +1)>9 ? date.getMonth() +1 : '0' + String(date.getMonth() +1)
			const nextMonth = (date.getMonth() + 2)>9 ? date.getMonth() + 2 : '0' + String(date.getMonth()+2)
			const day = (date.getDate())>9 ? date.getDate() : '0' + String(date.getDate())
			const hour = (date.getHours())>9 ? date.getHours() : '0' + String(date.getHours())
			const nextHour = (date.getHours() + 1)>9 ? (date.getHours() + 1) : '0' + String(date.getHours()+1)
			const minute  = date.getMinutes()
			const second = date.getSeconds()
			currentDate.currentDate = year + '-' + month + '-' + day
			currentDate.startDate = year + '-' + month + '-01'
			currentDate.endDate = year + '-' + nextMonth + '-01'
			currentDate.currentHour = hour + ':00'
			currentDate.nextDate = year + '-' + month + '-' + day
			currentDate.nextHour = nextHour + ':00'
			this.globalData.currentDate = currentDate
			this.globalData.currentDatetime = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
			this.globalData.currentDatetimeWithoutMinute = year + '-' + month + '-' + day + ' ' + hour + ':00:00'
			this.globalData.nextDatetimeWithoutMinute = year + '-' + month + '-' + day + ' ' + nextHour + ':00:00'
			this.globalData.currentStartDatetime = year + '-' + month + '01'
		},
		onShow: function() {},
		onHide: function() {
			uni.removeStorageSync('current_date')
			uni.removeStorageSync('current_date_index')
		}
	};
</script>

<style>
	/* 解决头条小程序组件内引入字体不生效的问题 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		src: url('/static/uni.ttf');
	}

	/* #endif */
	.container {
		background-color: #f5f8f5;
		font-size: 26rpx;
	}
</style>
